<?php
/**
 * @filename:					PriceAction.class.php
 * @desc:						墓地管理模块
 *
 * @author: 					张召
 * @copyright:					zhangzhao@huigeyuan.com
 * @date:						2011-05-04
 */


class PriceAction extends CommonAction
{
    function _initialize() {
		parent::_initialize();		
        $type = D('graveyard_type');
        $typename = $type->select();       

        $this->assign('typename',$typename);
		$state = D('graveyard_state');
        $statename = $state->select();
        $this->assign('statename',$statename);


        $garden = D('garden');
        $gardenname = $garden->select();
        $this->assign('gardenname',$gardenname);

    }
/**
    * 墓位定价信息一揽
    */
    function index()
    {
	/*
    	$crumb_info = array(
			array('uri' => '__URL__/info', 'title' => L('Graveyard_index'), 'sort' => C('CRUMB_LAST')),
		);

		$this->_mergeCrumbInfo($crumb_index);
		$this->_action_link = array(
			array('uri' => '__URL__/info', 'title' => L('list_Graveyard')),
		);
		$this->assign('crumb_info', $this->_crumb_info);
		$this->assign('action_link', $this->_action_link);
*/

		$this->display();
	}

	/**
    * 区域定价
    */
    function section()
    {
		$this->display();
    }
	function update2(){
	//dump($_POST);die;

		$districtid = $_POST['district_id'];
		$state_id = $_POST[state_id];
		$price = $_POST[price];
		$model = D ('graveyard');
		$qu = D ('district');

		$li = $qu->where("pid = '$districtid'")->select();//查询出排的id
	//	$l= $model->query("select * from gms_district d left join b on a.uid=b.uid")
		
		$newid  =array();
		foreach($li as $value)
		{
			$newid[]=$value["id"];
		}		
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		foreach ($newid as $val){
		    $list=$model->where(array('id' => $val[0]))->setField(array('state_id','price'),array("$state_id","$price"));
		}
		if (false !== $list) {
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('定价成功!');
		} else {
			$this->error ('定价失败!');
		}
	}


	/**
    * 单墓定价列表
    */
    function singlelist()
    {
		//传值id
		$id = $_POST['district_id']; 	
        
        $district = D('district');
		$districtname = $district->where("id=$id")->select();//查询所在区
		$this->assign('districtname',$districtname);
        $groupname = $district->where("pid=$id")->select();//查询排
        $this->assign('groupname',$groupname); 
        
        $graveyard = D('graveyard');
        $list = $graveyard->select();
        $this->assign('list',$list);
		$this->display();
    }
	/**
    * 单墓定价
    */
    function single()
    {
		$id = $_REQUEST['id'];
  		$this->assign('id',$id);
		$this->display();
    }
	function update1() {
		$model = D ( 'graveyard' );
		$state_id = $_POST[state_id];
		$price = $_POST[price];
		$id = $_REQUEST [id];
		$b=explode(',',$id);
		$newid  =array();
        foreach($b as $v){
        	$newid[] =array($v) ;
        }
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		foreach ($newid as $val){
		    $list=$model->where(array('id' => $val[0]))->setField(array('state_id','price'),array("$state_id","$price"));
		}
		if (false !== $list) {
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('定价成功!');
		} else {
			$this->error ('定价失败!');
		}
	}

	/**
    * 区域+墓型定价
    */
    function type()
    {
		$this->display();
    }
	function update3(){
	//dump($_POST);die;
		$districtid = $_POST['district_id'];
		$typeid = $_POST['type_id'];
		$state_id = $_POST[state_id];
		$price = $_POST[price];
		$model = D ('graveyard');
		$li = $model->where("district_id = '$districtid' and type_id='$typeid'")->select();
		$newid  =array();
		foreach($li as $value)
		{
			$newid[]=$value["id"];
		}
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		foreach ($newid as $val){
		    $list=$model->where(array('id' => $val[0]))->setField(array('state_id','price'),array("$state_id","$price"));
		}
		if (false !== $list) {
			$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
			$this->success ('定价成功!');
		} else {
			$this->error ('定价失败!');
		}

	}
}
?>